package com.worldwind.test;

import android.graphics.Typeface;

import com.R;

import java.util.ArrayList;

import gov.nasa.worldwind.formats.tiff.Type;
import gov.nasa.worldwind.geom.Offset;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.render.Color;
import gov.nasa.worldwind.render.ImageSource;
import gov.nasa.worldwind.shape.Label;
import gov.nasa.worldwind.shape.Path;
import gov.nasa.worldwind.shape.Placemark;
import gov.nasa.worldwind.shape.PlacemarkAttributes;
import gov.nasa.worldwind.shape.Polygon;
import gov.nasa.worldwind.shape.ShapeAttributes;
import gov.nasa.worldwind.shape.TextAttributes;

/**
 * Created by Lenovo on 2018/4/22.
 */

public class GeometryCreator {

    public Placemark createPlacemark(Position position, String displayName) {
        final double NORMAL_IMAGE_SCALE = 3.0;
        final double HIGHLIGHTED_IMAGE_SCALE = 4.0;
        PlacemarkAttributes placemarkAttributes =null;
        if (displayName.contains("体育馆")) {
            placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.sports));
        }else if(displayName.contains("行政楼")) {
            placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.admbuilding));
        }else if(displayName.contains("办公楼")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.officebuilding));
        }else if(displayName.contains("厕所")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.wc));
        }else if(displayName.contains("超市")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.supermarket));
        }else if(displayName.contains("打印店")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.print));
        }else if(displayName.contains("雕塑")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.sculpture));
        }else if(displayName.contains("多媒体")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.computer));
        }else if(displayName.contains("公寓楼")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.department));
        }else if(displayName.contains("广场")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.square));
        }else if(displayName.contains("健身房")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.fitnessroom));
        }else if(displayName.contains("讲堂")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.speech));
        }else if(displayName.contains("警务室")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.police));
        }else if(displayName.contains("俱乐部")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.club));
        }else if(displayName.contains("开水房")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.soilwater));
        }else if(displayName.contains("教学楼")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.teachbuilding));
        }else if(displayName.contains("垃圾箱")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.dustbin));
        }else if(displayName.contains("快递")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.expressage));
        }else if(displayName.contains("礼品店")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.gift));
        }else if(displayName.contains("理发店")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.cuthair));
        }else if(displayName.contains("路灯")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.light));
        }else if(displayName.contains("绿化")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.afforest));
        }else if(displayName.contains("沙滩排球")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.beachvolleyball));
        }else if(displayName.contains("排球")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.volleyball));
        }else if(displayName.contains("山丘")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.hill));
        }else if(displayName.contains("升旗台")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.redflag));
        }else if(displayName.contains("实验室")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.experiment));
        }else if(displayName.contains("食堂")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.canteen1));
        }else if(displayName.contains("书店")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.bookshop));
        }else if(displayName.contains("水果店")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.fruits));
        }else if(displayName.contains("停车场")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.parking));
        }else if(displayName.contains("移动")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.mobile));
        }else if(displayName.contains("联通")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.unicom));
        }else if(displayName.contains("电信")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.telecom));
        }else if(displayName.contains("图书馆")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.library));
        }else if(displayName.contains("网络中心")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.net));
        }else if(displayName.contains("维修部")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.repair));
        }else if(displayName.contains("洗衣房")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.washing));
        }else if(displayName.contains("消防栓")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.firefighting));
        }else if(displayName.contains("医务室")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.hospital));
        }else if(displayName.contains("浴室")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.showers));
        }else if(displayName.contains("钟楼")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.bellbuilding));
        }else if(displayName.contains("自行车停放点")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.bicycleparking));
        }else if(displayName.contains("当前位置")) {
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.location));
        }else{
                placemarkAttributes = PlacemarkAttributes.createWithImage(ImageSource.fromResource(R.drawable.defaultpoi));
        }
        Placemark placemark =new  Placemark(position,placemarkAttributes,displayName);
        placemark.getAttributes().setImageOffset(Offset.bottomCenter()).setImageScale(NORMAL_IMAGE_SCALE).setDrawLeader(true);
        placemark.setHighlightAttributes(new PlacemarkAttributes(placemark.getAttributes()).setImageScale(HIGHLIGHTED_IMAGE_SCALE));
        return placemark;
    }
    public Path createPolyline(ArrayList<Position> position) {
        Path polyline = new Path(position);
        ShapeAttributes attributes = new ShapeAttributes();
        attributes.setDrawVerticals(true); // display the extruded verticals
        attributes.setOutlineColor(new Color(0,0.8f,0.8f,1));
        attributes.setInteriorColor(new Color(1, 1, 1, 0.5f)); // 50% transparent white
        attributes.setOutlineWidth(6);
        polyline.setAttributes(attributes);
        ShapeAttributes highlightAttributes = new ShapeAttributes();
        highlightAttributes.setDrawVerticals(true); // display the extruded verticals
        highlightAttributes.setOutlineColor(new Color(1,0,0.8f,1));
        highlightAttributes.setInteriorColor(new Color(1, 1, 1, 0.5f)); // 50% transparent white
        highlightAttributes.setOutlineWidth(10);
        polyline.setHighlightAttributes(highlightAttributes);
        return polyline;
    }

    public Polygon createPolygon(ArrayList<Position> position) {
        Polygon polygon = new Polygon(position);
        ShapeAttributes attributes = new ShapeAttributes();
        attributes.setDrawVerticals(true); // display the extruded verticals
        attributes.setOutlineColor(new Color(0,0.8f,0.8f,1));
        attributes.setInteriorColor(new Color(1, 1, 1, 0.5f)); // 50% transparent white
        attributes.setOutlineWidth(6);
        polygon.setAttributes(attributes);
        ShapeAttributes highlightAttributes = new ShapeAttributes();
        highlightAttributes.setDrawVerticals(true); // display the extruded verticals
        highlightAttributes.setOutlineColor(new Color(1,0,0.8f,1));
        highlightAttributes.setInteriorColor(new Color(1, 1, 1, 0.5f)); // 50% transparent white
        highlightAttributes.setOutlineWidth(10);
        polygon.setHighlightAttributes(highlightAttributes);
        return polygon;
    }
    public Label createLabel(Position position,String displayContent){
        // Create a label with a 48 pixel text size and a bold typeface.
     /*   int bytes = displayContent.getBytes().length;
        if( bytes%3!=0){
            for(int i=0;i< bytes%3;i++) {
                displayContent = "";
            }
        }*/
        displayContent =".    "+displayContent+"    .";
        TextAttributes  attrs = new TextAttributes();
        attrs.setTypeface(Typeface.DEFAULT); // system default bold typeface
        attrs.setTextSize(24); // 48 screen pixels
        attrs.setTextOffset(Offset.topRight());
        attrs.setTextColor(new Color(0,1,0,1));
        Label  label = new Label(position, displayContent, attrs);
        return  label;
    }
}